﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

namespace Red.Scripts.Defines.Utilities
{
    public static class EnumExtensions
    {
        #region Public Functions

        public static string GetDescription( this Enum value )
        {
            Type type = value.GetType();
            FieldInfo field = type.GetField( value.ToString() );
            IEnumerable<DescriptionAttribute> attributes = field.GetCustomAttributes<DescriptionAttribute>();
            return attributes.FirstOrDefault()?.Description ?? string.Empty;
        }

        #endregion Public Functions
    }
}
